<?php

function unsDepartement_addSemester($name, $number, $formationID) {
    global $babDB;
    global $babBody;

    if (null != $name && null != $number && null != $formationID) {

        $babDB->db_query("INSERT INTO " . UNSDEPARTEMENT_SEMESTERS_TABLE_NAME ." VALUES (null, '".$name. "', ".$number. ", " . $formationID . ", now(), " . $GLOBALS['BAB_SESS_USERID'] . ");");

    } else {
        $babBody->addError(bab_translate("All fields are required!", $GLOBALS['babAddonFolder']));
    }
}

function unsDepartement_deleteSemester($id)
{
    global $babDB;
    
    $teachingUnitsList = unsDepartement_getTeachingUnitsForSemester($id);
    
    foreach ($teachingUnitsList as $teachingUnit)
    {
        unsDepartement_deleteTeachingUnit($teachingUnit['id']);
    }
    
    $babDB->db_query("delete from ".UNSDEPARTEMENT_SEMESTERS_TABLE_NAME." where id = ".$id);
}

function unsDepartement_getSemesterForFormation($id) {
    global $babDB;
    
    $res = $babDB->db_query("select * from " . UNSDEPARTEMENT_SEMESTERS_TABLE_NAME . " where semester_formationID = " . $id);

    $semesters = array();
    $i = 0;
    while ($arr = $babDB->db_fetch_array($res)) {
        $semesters[$i] = $arr;
        $i++;
    }
    return $semesters;
}

function unsDepartement_getSemester($id) {
    global $babDB;


    $res = $babDB->db_query("select * from " . UNSDEPARTEMENT_SEMESTERS_TABLE_NAME . " where id = " . $id);

    $semester = $babDB->db_fetch_array($res);
    return $semester;
}


?>
